<?php

namespace App\Models;

use App\Models\User;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{

    protected $fillable = ['title','content','image','user_id','category_id',
        'view_count','last_reply_user_id','reply_count','excerpt','slug'];

    public function user() {
        return $this->belongsTo(User::class,'user_id','id');
    }

    public function comments() {
        return $this->hasMany(Comment::class,'post_id','id');
    }

    public function category() {
        return $this->belongsTo(Category::class);
    }

    public function link($params = []) {
        return route('posts.show',array_merge([$this->id,$this->slug],$params));
    }
}
